<?php
/**
* Class Permiso.
*
* Implementation of the class Permiso.
*
* PHP version >= 5.1
*
* @category     FrameworkPunkuPHP
* @package      Model
* @author       Luis Fernando Almendras Aruzamen
* @copyright    2010 Luis Fernando Almendras Aruzamen
* @license      http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version      1.0
* @link         None
* @see          None
* @since        Available from the version  0.1 01-01-2010
* @deprecated   No
*/

/**
* Class Permiso
*
* Implementation of class Permiso.
*
* @category   WindowSI
* @package    Model
* @author     Luis Fernando Almendras Aruzamen
* @copyright  2010 Luis Fernando Almendras Aruzamen
* @license    http://creativecommons.org/licenses/by/3.0/legalcode  Creative Commons License Attribution 3.0 Unported
* @version    1.0
* @link       None
* @see        None
* @since      Available from the version  0.1 01-01-2010
* @deprecated No
*/
    class Permiso {
     // {{{ Constants

    /**
     * Constant for represent all registers.
     *
     * @access private
     */
     const ALL = -1;
     const VALUE = 1;
     const NONE = 0;
     // Operations
     const INSERT = "INSERT TABLE PERMISO";
     const UPDATE = "UPDATE TABLE PERMISO";
     const DELETE = "DELETE TABLE PERMISO";
     const SELECT = "SELECT TABLE PERMISO";
    // }}}

    // {{{ atributos

    /**
     * Variable instance Data Base.
     *
     * @var DataBase
     * @access private
     */
        private  $instanceDataBase;
    // }}}

    // {{{ constructores

    /**
     * This is construct base of the class.
     *
     * A public constructor; initializes the variable $instanceDataBase.
     *
     */
        public function __construct( $instanceDataBase ) {
            $this->instanceDataBase = $instanceDataBase;
        }
    // }}}

    // {{{ metodos

    /**
     * The implementation method for query to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function getListPermiso($idPermiso = self::ALL){
            $result = null;
            $query = null;
            try{
                $query = "SELECT pk_id_permiso, permiso, descripcion, estado_registro, fecha_transaccion, usuario_tran, transaccion_creacion, transaccion_modificacion ".
                         "FROM   seg_permiso ".
                         "WHERE  estado_registro = 'A' ";

                if( $idPermiso != self::ALL){
                $query = $query." AND pk_id_permiso = ?";
                $result = DataBase::getArrayListQuery($query, array($idPermiso), $this->instanceDataBase);
                }
                else{
                $result = DataBase::getArrayListQuery($query,array(), $this->instanceDataBase);
                }
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0941: '.$e->getMessage();
            }
            return $result;
        }

    /**
     * The implementation method for insert data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function insertPermiso($data){
            $result = null;
            $query = null;
            try{
                $query = "INSERT INTO seg_permiso( permiso, descripcion, estado_registro, fecha_transaccion, usuario_tran, transaccion_creacion, transaccion_modificacion) ".
                         "VALUES (?, ?, 'A',current_timestamp(), ?,  ?, ?)";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0932: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for delete data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function deletePermiso($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE seg_permiso ".
                         "SET estado_registro = 'E', ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_tran = ? ".
                         "WHERE pk_id_permiso = ? ";
                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);

            }
            catch(PDOException $e){
                echo 'Error JF-Model-0943: '.$e->getMessage();
            }
            return $result;
        }

     /**
     * The implementation method for update data to the instance data Base.
     *
     * @throws None.
     *
     * @access     public
     * @static     No.
     * @see        None.
     * @since      Available from the version  1.0 01-01-2010.
     * @deprecated No.
     */
        public function updatePermiso($data){
            $result = null;
            $query = null;
            try{
                $query = "UPDATE seg_permiso ".
                         "SET permiso = ? , descripcion = ?,  ".
                         "    transaccion_modificacion = ?, fecha_transaccion = current_timestamp(), usuario_tran = ? ".
                         "WHERE pk_id_permiso = ? ";

                DataBase::getBeginTransaction($this->instanceDataBase);
                $result = DataBase::getExecuteDML($query, $data,$this->instanceDataBase);
                DataBase::getCommitTransaction($this->instanceDataBase);
            }
            catch(PDOException $e){
                echo 'Error JF-Model-0944: '.$e->getMessage();
            }
            return $result;
        }
     // }}}
    }
?>
